<?php

namespace App\Http\Controllers\Auth;

use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Captcha;
use  Markdown;
use App\Http\Requests;

class AuthController extends Controller
{
	//登录成功的跳转位置
	protected $redirectPath = '/Admin'; 
    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */
    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        //$this->middleware('guest', ['except' => 'getLogout']);
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
    	$messages = [
    	'required'    		    =>  ' :attribute  是必填字典',
    	'email'    		        =>  ' :attribute  邮箱输入错误',
    	'min'      				=>  ' :attribute  密码6 位',
    	];
    	
        return Validator::make($data, [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|confirmed|min:6',
        	'verify' => 'required',
        ],$messages);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
    	
    	//插入主表
        $user = User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
        ]);
        
        //插入附表 user_info  url = $user->id;
/*         $user_info[];
        $user_info['sex'] =  $data['sex'];
        $user_info['age'] =  $data['age'];
        $user_info['uid'] =  $user->id;
               
        DB::table('user_info')->insert('$user_info'); */
        
        return $user;
    }
    
    //生成验证码
    public function Verify()
    {
    	return Captcha::src();
    }
    
    //判断验证码
    public function VerifyCode($code)
    {
    	return Captcha::check($code);
    }
    
    
    
}
